import React, { Component } from 'react';
class DemoSetStateSync extends Component {
    state = {
        count: 0
    }
    /*
     * setState处在同步的逻辑中，异步更新状态，更新真实dom
    */
    handleFn = () => {
        this.setState({
            count: this.state.count + 1
        })
        console.log('count=', this.state.count) // 0
        this.setState({
            count: this.state.count + 1
        })
        console.log('count=', this.state.count) // 0
        this.setState({
            count: this.state.count + 1
        })
        console.log('count=', this.state.count) // 0
        console.log('======')
    }
    render() {
        console.log('render')
        return (<div>
            <h3>08.setState同步异步</h3>
            count: {this.state.count}
            <button onClick={this.handleFn}>count++</button>

        </div >);
    }
}

export default DemoSetStateSync;